package com.admin.service.impl;

import com.admin.entity.Class;
import com.admin.dao.ClassMapper;
import com.admin.service.ClassService;
import com.admin.vo.query.ClassQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author szy
 * @since 2023-02-21
 */
@Service
@Transactional
public class ClassServiceImpl extends ServiceImpl<ClassMapper, Class> implements ClassService {

    @Override
    public IPage<Class> getClassByPage(IPage<Class> page, ClassQueryVo classQueryVo) {
        //创建条件构造器对象
        QueryWrapper<Class> queryWrapper = new QueryWrapper<Class>();
        //班级名
        queryWrapper.like(!ObjectUtils.isEmpty(classQueryVo.getClassName()),
                "class_name",classQueryVo.getClassName());
        //学院
        queryWrapper.eq(!ObjectUtils.isEmpty(classQueryVo.getCollegeId()),
                "college_id",classQueryVo.getCollegeId());
        //查询并返回数据
        return baseMapper.selectPage(page,queryWrapper);
    }
}
